package com.newy.dao.misc;

import java.util.List;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.newy.core.hibernate.CnOrder;
import com.newy.core.hibernate.HibernateDao;
import com.newy.domain.misc.FqaType;

/**
 * 
 * @author linzongxue 2012-2-19
 *
 */
@Repository
public class FqaTypeDao extends HibernateDao<FqaType, Long> {
	/**
	 * 获取指定类型的所有子类型
	 */
	public List<FqaType> getAllChildren(Long parentId){
		FqaType parent = this.get(parentId);
		return this.find(Restrictions.like("parentIdPath", parent.getParentIdPath() + parentId + "/%"), 
				Order.asc("parentIdPath"));
	}
	
	/**
	 * 获取指定类型的直接子类型
	 */
	public List<FqaType> getChildren(Long parentId){
		return this.find(Restrictions.eq("parentId", parentId), CnOrder.asc("name"));
	}
}
